<!--
  @Descripttion:：企业端-个人中心，修改企业用户信息
  @Author：yejianbo
  @Date：2022年10月20日 16:24:07
-->
<template>
  <div class="app-container">
    <p>填写用户信息</p>
    <el-form
      ref="userForm"
      :model="userForm"
      :rules="rules"
      label-width="80px"
    >
      <el-form-item label="姓名" prop="nickname">
        <el-input
          v-model="userForm.nickname"
          style="width: 50%"
          disabled
          placeholder="请输入姓名"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phoneNumber">
        <el-input
          v-model="userForm.phoneNumber"
          disabled
          style="width: 50%"
          placeholder="请输入手机号"
        />
      </el-form-item>
      <el-form-item label="部门" prop="deptName">
        <el-input
          v-model="userForm.deptName"
          disabled
          style="width: 50%"
          placeholder="请输入部门"
        />
      </el-form-item>
      <el-form-item label="职位" prop="remark">
        <el-input
          v-model="userForm.remark"
          disabled
          style="width: 50%"
          placeholder="请输入职位"
        />
      </el-form-item>
      <el-form-item label="邮箱号" prop="email">
        <el-input
          v-model="userForm.email"
          disabled
          style="width: 50%"
          placeholder="请输入邮箱号"
        />
      </el-form-item>
    </el-form>
    <!-- <el-row type="flex">
      <el-button type="primary" @click="submitUserForm">提 交</el-button>
    </el-row> -->
  </div>
</template>

<script>
import { getUserConfig } from '@/api/company-admin-api/userManage'
export default {
  name: 'Company',
  data() {
    const validatePhone = (rule, value, callback) => {
      const phoneReg = /^[1][0-9]{10}$/
      if (value === '') {
        return callback(new Error('手机号不能为空'))
      } else {
        if (phoneReg.test(value)) {
          return callback()
        } else {
          return callback(new Error('格式有误'))
        }
      }
    }
    const validataEmail = (rule, value, callback) => {
      const emailReg =
          /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
      if (value === '') {
        return callback(new Error('邮箱不可为空'))
      } else {
        if (emailReg.test(value)) {
          return callback()
        } else {
          return callback(new Error('格式有误'))
        }
      }
    }
    return {
      pickerOptionStop: {
        disabledDate: (time) => {
          const newTime = new Date()
          return time.getTime() >= newTime
        }
      },
      // 遮罩层
      loading: true,
      // 用户信息表
      userForm: {
        nickname: '', // 企业申请人姓名
        deptName: '', // 部门
        remark: '', // 职位
        email: '', // 邮箱
        phoneNumber: '' // 手机号
      },
      // 表单校验
      rules: {
        nickname: [
          {
            required: true,
            message: '企业申请人姓名不能为空',
            trigger: 'blur'
          }
        ],
        phoneNumber: [
          { required: true, validator: validatePhone, trigger: 'blur' }
        ],
        email: [{ required: true, validator: validataEmail, trigger: 'blur' }],
        deptName: [{ required: true, message: '部门不能为空', trigger: 'blur' }],
        remark: [{ required: true, message: '职位不能为空', trigger: 'blur' }]
      },
      companyLoginPhone: '' // 用户登录的手机号，自动回填，禁止编辑
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      getUserConfig().then(res => {
        if (res.code === 0 && res.data) {
          for (const key in res.data) {
            this.userForm[key] = res.data[key]
          }
        }
        this.companyLoginPhone = localStorage.getItem('companyLoginPhone') || ''
        if (this.companyLoginPhone) {
          this.userForm.phoneNumber = this.companyLoginPhone + ''
        }
      })
    }
  }
}
</script>

